package com.xinyue.center.service.manager;

import com.xinyue.center.common.GameCenterError;
import com.xinyue.center.dao.entity.Account;
import com.xinyue.center.messages.request.RegisterRequest;
import com.xinyue.game.common.SystemContext;
import org.apache.commons.lang3.StringUtils;

/**
 * @Author 王广帅
 * @Date 2020/12/26 18:31
 */
public class AccountRegisterManager {


    public Account buildAccount(RegisterRequest param, String accountId) {
        String userName = param.getUsername();
        Account account = new Account();
        account.setId(accountId);
        account.setUsername(userName);
        account.setUsername(param.getUsername());
        account.setPassword(param.getPassword());
        account.setRegisterIP(param.getRegisterIp());
        long registerTime = SystemContext.getCurrentMillTime();
        account.setCreateTime(registerTime);
        return account;
    }

    public void checkUsername(String username) {
        if (StringUtils.isBlank(username)) {
            throw GameCenterError.USERNAME_NULL.newException();
        }
        int len = username.length();
        //正式中可以将此处修改为从配置中读取
        if (len > 20 || len < 5) {
            throw GameCenterError.USERNAME_LENGTH_ERROR.newException();
        }
        //TODO 非法字符验证也要添加
        //以及其它的检测验证
    }

    public void checkPassword(String password) {
        if (StringUtils.isBlank(password)) {
            throw GameCenterError.PASSWORD_NULL.newException();
        }
        int len = password.length();
        if (len > 20 || len < 5) {
            throw GameCenterError.PASSWORD_LENGTH_ERROR.newException();
        }
        //TODO 添加其它验证
    }


}
